package com.example.controller;

import com.alibaba.fastjson.JSON;
import com.example.pojo.Musiclist;
import com.example.service.musicListImp;
import com.example.utils.ResponseMessage;
import com.example.utils.ResultUtil;
import org.apache.tomcat.util.http.parser.MediaType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//@RestController
@Controller
@ResponseBody
@CrossOrigin(origins = "*", maxAge = 3600)
public class musiclist {
    @Autowired
    private musicListImp list1;

    @GetMapping("/get")
    public String getlist() {
        return "ren545451";
    }

    @GetMapping(value = "/getAll")
    public ResponseMessage musiclist() {
        List<Musiclist> list = list1.getlist();
        ResponseMessage message = null;
        int size = list.size();
        if (size >= 0) {
            message = ResultUtil.success(list, size);
        } else {
            message = ResultUtil.error(400, "查询错误");
        }
        return message;
    }

    @GetMapping(value = "/getAllToString")
    public ResponseMessage musiclistToString() {
        List<Musiclist> list = list1.getlist();
//        System.out.println(list);
        int size = list.size();
        ResponseMessage message = null;
        if (size >= 0) {
            message = ResultUtil.success(list, size);
        } else {
            message = ResultUtil.error(400, "查询错误");
        }
//        System.out.println(message);
        return message;
    }

    @RequestMapping (value = "/addMusic1", headers = " 'content-type': 'application/json'")
    public String addMusic(@RequestBody Map<String, String> params) {
        String musicer = params.get("Musicer");
        String musicName = params.get("MusicName");
        String musicUrl = params.get("MusicUrl");
        String res = list1.addMusic(musicer, musicName, musicUrl);
        return res;
    }
}
